package xmldatabase;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author betty
 */
public class InsertDB {

    // 连接对象
    private Connection conn;
    // 传递sql语句
    private Statement stt = null;

    ResultSet rs;
    // 查询



    public void ins(Newuser usertest) throws ClassNotFoundException, SQLException {

        conn = DBConnection.getConnection();
        stt = conn.createStatement();
        if (conn == null) {
            return;
        }

     String sql = "INSERT INTO news(position,phonenumber,email,gender,id,name,password) VALUES (?,?,?,?,?,?,?)";
            // 预处理sql语句
            PreparedStatement presta = conn.prepareStatement(sql);
            // 设置sql语句中的values值
            presta.setInt(1, usertest.pos);
            presta.setString(2, usertest.phnu);
            presta.setString(3, usertest.em);
            presta.setString(4, usertest.gen);
            presta.setInt(5, usertest.id);
            presta.setString(6, usertest.nm);
            presta.setString(7, usertest.pw);
            // 执行SQL语句，实现数据添加
            presta.execute();
        } 
    }